# Copyright (C) 2014-2021  CEA/DEN, EDF R&D
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
#
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#

from SketchAPI import *

from salome.shaper import model

model.begin()
partSet = model.moduleDocument()
model.addParameter(partSet, "ShaftSize", "16")
model.addParameter(partSet, "ShaftChamfer", "0.2")
model.addParameter(partSet, "ToolHeight", "5")
model.addParameter(partSet, "ToolDraftAngle", "11")
model.addParameter(partSet, "ScrewDiam", "3.5")
model.addParameter(partSet, "ThreadDiam", "ScrewDiam+1")
model.addParameter(partSet, "ScrewHeight", "12")
model.addParameter(partSet, "ToolEdgeSize", "9")
Sketch_1 = model.addSketch(partSet, model.defaultPlane("YOZ"))
SketchLine_1 = Sketch_1.addLine(7.8, 0, -7.8, 0)
SketchLine_2 = Sketch_1.addLine(-8, 0.2, -8, 15.8)
SketchLine_3 = Sketch_1.addLine(-7.8, 16, 7.8, 16)
SketchLine_4 = Sketch_1.addLine(8, 15.8, 8, 0.2)
SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result())
SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_3.result())
SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_4.result())
SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "Origin"), False)
SketchPoint_1 = SketchProjection_1.createdFeature()
SketchConstraintMiddle_1 = Sketch_1.setMiddlePoint(SketchAPI_Point(SketchPoint_1).coordinates(), SketchLine_1.result())
SketchConstraintEqual_1 = Sketch_1.setEqual(SketchLine_2.result(), SketchLine_1.result())
SketchLine_5 = Sketch_1.addLine(-8, 0.2, -7.8, 0)
SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_2.startPoint(), SketchLine_5.startPoint())
SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_5.endPoint())
SketchLine_6 = Sketch_1.addLine(7.8, 0, 8, 0.2)
SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchLine_6.startPoint())
SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_6.endPoint())
SketchLine_7 = Sketch_1.addLine(-8, 15.8, -7.8, 16)
SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_7.startPoint())
SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_3.startPoint(), SketchLine_7.endPoint())
SketchLine_8 = Sketch_1.addLine(7.8, 16, 8, 15.8)
SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_8.startPoint())
SketchConstraintCoincidence_8 = Sketch_1.setCoincident(SketchLine_4.startPoint(), SketchLine_8.endPoint())
SketchConstraintEqual_2 = Sketch_1.setEqual(SketchLine_2.result(), SketchLine_3.result())
SketchConstraintEqual_3 = Sketch_1.setEqual(SketchLine_3.result(), SketchLine_4.result())
SketchConstraintEqual_4 = Sketch_1.setEqual(SketchLine_5.result(), SketchLine_6.result())
SketchConstraintEqual_5 = Sketch_1.setEqual(SketchLine_6.result(), SketchLine_7.result())
SketchConstraintEqual_6 = Sketch_1.setEqual(SketchLine_7.result(), SketchLine_8.result())
SketchConstraintDistance_1 = Sketch_1.setDistance(SketchLine_5.startPoint(), SketchLine_4.result(), "ShaftSize", True)
SketchConstraintDistance_2 = Sketch_1.setDistance(SketchLine_1.endPoint(), SketchLine_3.result(), "ShaftSize", True)
SketchConstraintDistanceHorizontal_1 = Sketch_1.setHorizontalDistance(SketchLine_5.startPoint(), SketchLine_1.endPoint(), "ShaftChamfer")
SketchConstraintDistanceVertical_1 = Sketch_1.setVerticalDistance(SketchLine_1.endPoint(), SketchLine_5.startPoint(), "ShaftChamfer")
model.do()
Part_1 = model.addPart(partSet)
Part_1.setName("TurnShaft")
Part_1.result().setName("TurnShaft")
Part_1.result().setColor(75, 75, 75)
Part_1_doc = Part_1.document()
Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "PartSet/Sketch_1/Face-SketchLine_6f-SketchLine_4r-SketchLine_8r-SketchLine_3r-SketchLine_7r-SketchLine_2r-SketchLine_5f-SketchLine_1r")], model.selection(), 100, 0)
ExtrusionCut_1 = model.addExtrusionCut(Part_1_doc, [], model.selection(), model.selection("FACE", "Extrusion_1_1/Generated_Face&PartSet/Sketch_1/SketchLine_4"), 0, model.selection(), 0, [model.selection("SOLID", "Extrusion_1_1")])
Sketch_2 = model.addSketch(Part_1_doc, model.selection("FACE", "Extrusion_1_1/Generated_Face&PartSet/Sketch_1/SketchLine_2"))
SketchProjection_2 = Sketch_2.addProjection(model.selection("EDGE", "PartSet/Sketch_1/SketchLine_7"), True)
SketchLine_9 = SketchProjection_2.createdFeature()
SketchLine_10 = Sketch_2.addLine(0, 15.8, 0.2, 16)
SketchConstraintCoincidence_9 = Sketch_2.setCoincident(SketchAPI_Line(SketchLine_9).startPoint(), SketchLine_10.startPoint())
SketchLine_11 = Sketch_2.addLine(0.2, 16, 0, 16)
SketchConstraintCoincidence_10 = Sketch_2.setCoincident(SketchLine_10.endPoint(), SketchLine_11.startPoint())
SketchConstraintCoincidence_11 = Sketch_2.setCoincident(SketchAPI_Line(SketchLine_9).endPoint(), SketchLine_11.endPoint())
SketchConstraintHorizontal_3 = Sketch_2.setHorizontal(SketchLine_11.result())
SketchConstraintEqual_7 = Sketch_2.setEqual(SketchLine_9.result(), SketchLine_11.result())
SketchProjection_3 = Sketch_2.addProjection(model.selection("EDGE", "PartSet/Sketch_1/SketchLine_5"), True)
SketchLine_12 = SketchProjection_3.createdFeature()
SketchLine_13 = Sketch_2.addLine(0, 0.2, 0.2, 0)
SketchConstraintCoincidence_12 = Sketch_2.setCoincident(SketchAPI_Line(SketchLine_12).startPoint(), SketchLine_13.startPoint())
SketchLine_14 = Sketch_2.addLine(0.2, 0, 0, 0)
SketchConstraintCoincidence_13 = Sketch_2.setCoincident(SketchLine_13.endPoint(), SketchLine_14.startPoint())
SketchConstraintCoincidence_14 = Sketch_2.setCoincident(SketchAPI_Line(SketchLine_12).endPoint(), SketchLine_14.endPoint())
SketchConstraintHorizontal_4 = Sketch_2.setHorizontal(SketchLine_14.result())
SketchConstraintEqual_8 = Sketch_2.setEqual(SketchLine_12.result(), SketchLine_14.result())
ExtrusionCut_1.setNestedSketch(Sketch_2)
ExtrusionCut_2 = model.addExtrusionCut(Part_1_doc, [], model.selection(), model.selection("FACE", "ExtrusionCut_1_1/Modified_Face&PartSet/Sketch_1/SketchLine_1"), 0, model.selection(), 0, [model.selection("SOLID", "ExtrusionCut_1_1")])
Sketch_3 = model.addSketch(Part_1_doc, model.selection("FACE", "ExtrusionCut_1_1/Modified_Face&PartSet/Sketch_1/SketchLine_3"))
SketchProjection_4 = Sketch_3.addProjection(model.selection("EDGE", "[ExtrusionCut_1_1/Modified_Face&PartSet/Sketch_1/SketchLine_3][ExtrusionCut_1_1/Generated_Face&Sketch_1/SketchLine_2]"), False)
SketchLine_15 = SketchProjection_4.createdFeature()
SketchProjection_5 = Sketch_3.addProjection(model.selection("VERTEX", "PartSet/Sketch_1/SketchLine_2_EndVertex"), False)
SketchPoint_2 = SketchProjection_5.createdFeature()
SketchLine_16 = Sketch_3.addLine(0, -8, 0.2, -8)
SketchConstraintCoincidence_15 = Sketch_3.setCoincident(SketchAPI_Point(SketchPoint_2).coordinates(), SketchLine_16.startPoint())
SketchLine_17 = Sketch_3.addLine(0.2, -8, 0, -7.8)
SketchConstraintCoincidence_16 = Sketch_3.setCoincident(SketchLine_16.endPoint(), SketchLine_17.startPoint())
SketchLine_18 = Sketch_3.addLine(0, -7.8, 0, -8)
SketchConstraintCoincidence_17 = Sketch_3.setCoincident(SketchLine_17.endPoint(), SketchLine_18.startPoint())
SketchConstraintCoincidence_18 = Sketch_3.setCoincident(SketchAPI_Point(SketchPoint_2).coordinates(), SketchLine_18.endPoint())
SketchConstraintHorizontal_5 = Sketch_3.setHorizontal(SketchLine_16.result())
SketchConstraintVertical_3 = Sketch_3.setVertical(SketchLine_18.result())
SketchConstraintEqual_9 = Sketch_3.setEqual(SketchLine_16.result(), SketchLine_18.result())
SketchConstraintCoincidence_19 = Sketch_3.setCoincident(SketchLine_16.endPoint(), SketchLine_15.result())
SketchProjection_6 = Sketch_3.addProjection(model.selection("VERTEX", "PartSet/Sketch_1/SketchLine_8_EndVertex"), False)
SketchPoint_3 = SketchProjection_6.createdFeature()
SketchLine_19 = Sketch_3.addLine(0, 8, 0, 7.8)
SketchConstraintCoincidence_20 = Sketch_3.setCoincident(SketchAPI_Point(SketchPoint_3).coordinates(), SketchLine_19.startPoint())
SketchLine_20 = Sketch_3.addLine(0, 7.8, 0.2, 8)
SketchConstraintCoincidence_21 = Sketch_3.setCoincident(SketchLine_19.endPoint(), SketchLine_20.startPoint())
SketchLine_21 = Sketch_3.addLine(0.2, 8, 0, 8)
SketchConstraintCoincidence_22 = Sketch_3.setCoincident(SketchLine_20.endPoint(), SketchLine_21.startPoint())
SketchConstraintCoincidence_23 = Sketch_3.setCoincident(SketchAPI_Point(SketchPoint_3).coordinates(), SketchLine_21.endPoint())
SketchConstraintVertical_4 = Sketch_3.setVertical(SketchLine_19.result())
SketchConstraintHorizontal_6 = Sketch_3.setHorizontal(SketchLine_21.result())
SketchConstraintEqual_10 = Sketch_3.setEqual(SketchLine_19.result(), SketchLine_21.result())
SketchConstraintCoincidence_24 = Sketch_3.setCoincident(SketchLine_20.endPoint(), SketchLine_15.result())
ExtrusionCut_2.setNestedSketch(Sketch_3)
ExtrusionCut_3 = model.addExtrusionCut(Part_1_doc, [], model.selection(), 0, 3, [model.selection("SOLID", "ExtrusionCut_2_1")])
Sketch_4 = model.addSketch(Part_1_doc, model.selection("FACE", "ExtrusionCut_1_1/Modified_Face&PartSet/Sketch_1/SketchLine_3"))
SketchCircle_1 = Sketch_4.addCircle(10, 0, 5)
SketchProjection_7 = Sketch_4.addProjection(model.selection("EDGE", "[ExtrusionCut_2_1/Modified_Face&Extrusion_1_1/From_Face][ExtrusionCut_2_1/Modified_Face&Sketch_1/SketchLine_2]"), False)
SketchLine_22 = SketchProjection_7.createdFeature()
SketchLine_23 = Sketch_4.addLine(10, 0, 0, 0)
SketchLine_23.setAuxiliary(True)
SketchConstraintCoincidence_25 = Sketch_4.setCoincident(SketchCircle_1.center(), SketchLine_23.startPoint())
SketchConstraintCoincidence_26 = Sketch_4.setCoincident(SketchLine_23.endPoint(), SketchLine_22.result())
SketchConstraintMiddle_2 = Sketch_4.setMiddlePoint(SketchLine_23.endPoint(), SketchLine_22.result())
SketchConstraintPerpendicular_1 = Sketch_4.setPerpendicular(SketchLine_23.result(), SketchLine_22.result())
SketchConstraintRadius_1 = Sketch_4.setRadius(SketchCircle_1.results()[1], 5)
SketchConstraintLength_1 = Sketch_4.setLength(SketchLine_23.result(), 10)
ExtrusionCut_3.setNestedSketch(Sketch_4)
model.do()
Part_2 = model.addPart(partSet)
Part_2.setName("Stamp")
Part_2.result().setName("Stamp")
Part_2_doc = Part_2.document()
Sketch_5 = model.addSketch(Part_2_doc, model.defaultPlane("XOZ"))
SketchProjection_8 = Sketch_5.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
SketchPoint_4 = SketchProjection_8.createdFeature()
SketchCircle_2 = Sketch_5.addCircle(0, 0, 5)
SketchConstraintCoincidence_27 = Sketch_5.setCoincident(SketchPoint_4.result(), SketchCircle_2.center())
SketchConstraintRadius_2 = Sketch_5.setRadius(SketchCircle_2.results()[1], 5)
model.do()
Extrusion_2 = model.addExtrusion(Part_2_doc, [model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2f")], model.selection(), 10, 0)
model.do()
Placement_1 = model.addPlacement(partSet, [model.selection("COMPOUND", "Stamp/")], model.selection("FACE", "Stamp/Extrusion_1_1/To_Face"), model.selection("FACE", "TurnShaft/ExtrusionCut_3_1/From_Face"), False, True)
model.end()

# check that names of selection are exported and imported correctly
assert(model.checkPythonDump())
